//
//  clock_os.c
//  electronic_clock
//
//  Created by fukai on 2018/10.
//  Copyright © 2018年 赛博智能车实验室. All rights reserved.
//

#include "clock_os.h"
#include "key.h"
#include "oled.h"


//时钟结构体初始化
ClockNode Clock =
{
	//时间
	.second = 50,
	.minute = 59,
	.hour = 23,
	.date = 9,
	.month = 11,
	.year = 2018,
	
	//秒表
	.stop_millisecond = 0,
	.stop_second = 0,
	.stop_minute = 0,
	.stop_hour = 0,
	
	//闹钟
	.alarm_minute = 30,
	.alarm_hour = 9,
	
	//计时器
	.timer_second = 0,
	.timer_minute = 0,
	.timer_hour = 0,
	
	//时钟部分
	.ClockWorkStatus = CLOCK_NORMAL,
	.TimeSet = HOUR_SET,
	.Week = Friday,
	.LeapYearStatus = NOT_LEAP_YEAR,
	
	//闹钟部分
	.AlarmClockWorkStatus = ALARM_START,
	.AlarmTimeSet = ALARM_MINUTE_SET,
	
	//秒表部分
	.StopWatchStatus = WATCH_STOP,
	
	//记时器部分
	.TimerWorkStatus = TIMER_STOP,
	.TimerSet = TIMER_HOUR_SET
};


//时钟显示结构体初始化
ClockDisplayNode ClockDisplay =
{
	.ClockDisplayStatus = MAIN_INTERFACE,
	.ClockMenuSelect = MENU_CLOCK_SET,
	.ClockTimeSetSelect = TIME_HOUR_SET,
	.ClockAlarmSetSelect = CLK_ALARM_HOUR_SET,
	.ClockTimerSetSelect = CLK_TIMER_HOUR_SET,
	
	.FlickerFlag = APPEAR
};


//闪烁显示标志切换
//用于中断中
//times:定时器中断计数次数
void FlickerShow(int times)
{
	static int t = 0;
	t++;
	if(t == times)
	{
		t = 0;
		switch(ClockDisplay.FlickerFlag)
		{
			case APPEAR:
				if(KeyMessage.long_press_mode == 0)//非长按状态下才启用闪烁
				{
					ClockDisplay.FlickerFlag = DISAPPEAR;
				}
				break;
			case DISAPPEAR:
				ClockDisplay.FlickerFlag = APPEAR;
				break;
		}
	}
}


//界面操作逻辑部分
//更改所在行，所在页
void FunctionSelection(void)
{
	KeyMessage.KeyValue = KeyScan();
	switch(KeyMessage.KeyValue)
	{
		case KEY_NULL:
			break;
		
		case KEY_MENU://菜单/确认键
			OledCls();//OLED清屏
			switch(ClockDisplay.ClockDisplayStatus)	//OLED屏幕上显示的界面
			{
				case MAIN_INTERFACE://主界面
					ClockDisplay.ClockMenuSelect = MENU_CLOCK_SET;
					ClockDisplay.ClockDisplayStatus = MENU;
					break;
				
				case MENU://菜单功能选择界面
					switch(ClockDisplay.ClockMenuSelect)//菜单选择的指向
					{
						case MENU_CLOCK_SET:
							Clock.ClockWorkStatus = CLOCK_SETTING;//时钟工作状态切换为设置状态
							ClockDisplay.ClockTimeSetSelect = TIME_HOUR_SET;
							ClockDisplay.ClockDisplayStatus = CLOCK_SET;//进入时间设置界面
							break;
						case MENU_ALARM_SET:
							ClockDisplay.ClockAlarmSetSelect = CLK_ALARM_HOUR_SET;
							ClockDisplay.ClockDisplayStatus = ALARM_SET;
							break;
						case MENU_STOP_WATCH:
							ClockDisplay.ClockDisplayStatus = STOP_WATCH;
							break;
						case MENU_TIMER_SET:
							ClockDisplay.ClockTimerSetSelect = CLK_TIMER_HOUR_SET;
							ClockDisplay.ClockDisplayStatus = TIMER_SET;
							break;
					}
					break;
					
				case CLOCK_SET://时间设置界面
					Clock.ClockWorkStatus = CLOCK_NORMAL;//时钟工作状态切换为正常状态
					ClockDisplay.ClockDisplayStatus = MENU;
					break;
				
				case ALARM_SET://闹钟设置界面
					switch(Clock.AlarmClockWorkStatus)
					{
						case ALARM_STOP:
							Clock.AlarmClockWorkStatus = ALARM_START;
							break;
						case ALARM_START:
							Clock.AlarmClockWorkStatus = ALARM_STOP;
							break;
						case ALARM_WORKING:
							Clock.AlarmClockWorkStatus = ALARM_STOP;
							break;
					}
					break;
				
				case STOP_WATCH://秒表设置
					switch(Clock.StopWatchStatus)
					{
						case WATCH_STOP://秒表停止工作
							Clock.StopWatchStatus = WATCH_START;
							break;
						case WATCH_START://秒表开始工作
							Clock.StopWatchStatus = WATCH_PAUSE;
							break;
						case WATCH_PAUSE://秒表暂停
							Clock.StopWatchStatus = WATCH_START;
							break;
					}
					break;
				
				case TIMER_SET://计时器设置
					switch(Clock.TimerWorkStatus)
					{
						case TIMER_STOP:
							Clock.TimerWorkStatus = TIMER_START;
							break;
						case TIMER_START:
							Clock.TimerWorkStatus = TIMER_STOP;
							break;
						case TIMER_ALARM:
							Clock.TimerWorkStatus = TIMER_STOP;
							break;
					}
					break;
				
				case INFO://制作者信息
					break;
			}
			break;
			
		case KEY_BACK:
			OledCls();//OLED清屏
			switch(ClockDisplay.ClockDisplayStatus)//OLED屏幕上显示的界面
			{
				case MAIN_INTERFACE://主界面
					ClockDisplay.ClockDisplayStatus = INFO;
					break;
				
				case MENU://菜单功能选择界面
					ClockDisplay.ClockDisplayStatus = MAIN_INTERFACE;
					break;
				
				case CLOCK_SET://时间设置界面
					break;
				
				case ALARM_SET://闹钟设置界面
					switch(Clock.AlarmClockWorkStatus)
					{
						case ALARM_STOP:
							ClockDisplay.ClockDisplayStatus = MENU;
							break;
						case ALARM_START:
							ClockDisplay.ClockDisplayStatus = MENU;
							break;
						case ALARM_WORKING:
							break;
					}
					break;
				
				case STOP_WATCH://秒表设置
					switch(Clock.StopWatchStatus)
					{
						case WATCH_STOP://秒表停止工作
							ClockDisplay.ClockDisplayStatus = MENU;
							break;
						case WATCH_START://秒表开始工作
							ClockDisplay.ClockDisplayStatus = MENU;
							break;
						case WATCH_PAUSE://秒表暂停
							Clock.StopWatchStatus = WATCH_STOP;
							break;
					}
					break;
				
				case TIMER_SET://计时器设置
					switch(Clock.TimerWorkStatus)
					{
						case TIMER_STOP:
							//计时器示数清零
							Clock.timer_hour = 0;
							Clock.timer_minute = 0;
							Clock.timer_second = 0;
							ClockDisplay.ClockDisplayStatus = MENU;
							break;
						case TIMER_START:
							ClockDisplay.ClockDisplayStatus = MENU;
							break;
						case TIMER_ALARM:
							break;
					}
					break;
				
				case INFO://制作者信息
					ClockDisplay.ClockDisplayStatus = MAIN_INTERFACE;
					break;
			}
			break;
			
		case KEY_DIRECTION_UP:	//方向键上
			OledCls();//OLED清屏
			switch(ClockDisplay.ClockDisplayStatus)//OLED屏幕上显示的界面
			{
				case MAIN_INTERFACE://主界面
					break;
				
				case MENU://菜单功能选择界面
					ClockDisplay.ClockMenuSelect--;
					if(ClockDisplay.ClockMenuSelect < MENU_CLOCK_SET)
					{
						ClockDisplay.ClockMenuSelect = MENU_CLOCK_SET;
					}
					break;
				
				case CLOCK_SET://时间设置界面
					switch(ClockDisplay.ClockTimeSetSelect)
					{
						case TIME_HOUR_SET:
							Clock.TimeSet = HOUR_SET;
							break;
						case TIME_MINUTE_SET:
							Clock.TimeSet = MINUTE_SET;
							break;
						case TIME_SECOND_SET:
							Clock.TimeSet = SECOND_SET;
							break;
						case TIME_WEEK_SET:
							Clock.TimeSet = WEEK_SET;
							break;
						case TIME_YEAR_SET:
							Clock.TimeSet = YEAR_SET;
							break;
						case TIME_MONTH_SET:
							Clock.TimeSet = MONTH_SET;
							break;
						case TIME_DATE_SET:
							Clock.TimeSet = DATE_SET;
							break;
					}
					TimeAddSet(&Clock);
					break;
				
				case ALARM_SET://闹钟设置界面
					switch(Clock.AlarmClockWorkStatus)
					{
						case ALARM_STOP:
							switch(ClockDisplay.ClockAlarmSetSelect)
							{
								case CLK_ALARM_HOUR_SET:
									Clock.AlarmTimeSet = ALARM_HOUR_SET;
									break;
								case CLK_ALARM_MINUTE_SET:
									Clock.AlarmTimeSet = ALARM_MINUTE_SET;
									break;
							}
							AlarmAddSet(&Clock);
							break;
						case ALARM_START:
							break;
						case ALARM_WORKING:
							break;
					}
					break;
				
				case STOP_WATCH://秒表设置
					break;
				
				case TIMER_SET://计时器设置
					switch(Clock.TimerWorkStatus)
					{
						case TIMER_STOP:
							switch(ClockDisplay.ClockTimerSetSelect)
							{
								case CLK_TIMER_HOUR_SET:
									Clock.TimerSet = TIMER_HOUR_SET;
									break;
								case CLK_TIMER_MINUTE_SET:
									Clock.TimerSet = TIMER_MINUTE_SET;
									break;
								case CLK_TIMER_SECOND_SET:
									Clock.TimerSet = TIMER_SECOND_SET;
									break;
							}
							TimerAddSet(&Clock);
							break;
						case TIMER_START:
							break;
						case TIMER_ALARM:
							break;
					}
					break;
				
				case INFO://制作者信息
					break;
			}
			break;
			
		case KEY_DIRECTION_DOWN:	//方向键下
			OledCls();//OLED清屏
			switch(ClockDisplay.ClockDisplayStatus)//OLED屏幕上显示的界面
			{
				case MAIN_INTERFACE://主界面
					break;
				
				case MENU://菜单功能选择界面
					ClockDisplay.ClockMenuSelect++;
					if(ClockDisplay.ClockMenuSelect > MENU_TIMER_SET)
					{
						ClockDisplay.ClockMenuSelect = MENU_TIMER_SET;
					}
					break;
				
				case CLOCK_SET://时间设置界面
					switch(ClockDisplay.ClockTimeSetSelect)
					{
						case TIME_HOUR_SET:
							Clock.TimeSet = HOUR_SET;
							break;
						case TIME_MINUTE_SET:
							Clock.TimeSet = MINUTE_SET;
							break;
						case TIME_SECOND_SET:
							Clock.TimeSet = SECOND_SET;
							break;
						case TIME_WEEK_SET:
							Clock.TimeSet = WEEK_SET;
							break;
						case TIME_YEAR_SET:
							Clock.TimeSet = YEAR_SET;
							break;
						case TIME_MONTH_SET:
							Clock.TimeSet = MONTH_SET;
							break;
						case TIME_DATE_SET:
							Clock.TimeSet = DATE_SET;
							break;
					}
					TimeDecreaseSet(&Clock);
					break;
				
				case ALARM_SET://闹钟设置界面
					switch(Clock.AlarmClockWorkStatus)
					{
						case ALARM_STOP:
							switch(ClockDisplay.ClockAlarmSetSelect)
							{
								case CLK_ALARM_HOUR_SET:
									Clock.AlarmTimeSet = ALARM_HOUR_SET;
									break;
								case CLK_ALARM_MINUTE_SET:
									Clock.AlarmTimeSet = ALARM_MINUTE_SET;
									break;
							}
							AlarmDecreaseSet(&Clock);
							break;
						case ALARM_START:
							break;
						case ALARM_WORKING:
							break;
					}
					break;
				
				case STOP_WATCH://秒表设置
					break;
				
				case TIMER_SET://计时器设置
					switch(Clock.TimerWorkStatus)
					{
						case TIMER_STOP:
							switch(ClockDisplay.ClockTimerSetSelect)
							{
								case CLK_TIMER_HOUR_SET:
									Clock.TimerSet = TIMER_HOUR_SET;
									break;
								case CLK_TIMER_MINUTE_SET:
									Clock.TimerSet = TIMER_MINUTE_SET;
									break;
								case CLK_TIMER_SECOND_SET:
									Clock.TimerSet = TIMER_SECOND_SET;
									break;
							}
							TimerDecreaseSet(&Clock);
							break;
						case TIMER_START:
							break;
						case TIMER_ALARM:
							break;
					}
					break;
				
				case INFO://制作者信息
					break;
			}
			break;
			
		case KEY_DIRECTION_LEFT://方向键左
			OledCls();//OLED清屏
			switch(ClockDisplay.ClockDisplayStatus)//OLED屏幕上显示的界面
			{
				case MAIN_INTERFACE://主界面
					break;
				
				case MENU://菜单功能选择界面
					break;
				
				case CLOCK_SET://时间设置界面
					ClockDisplay.ClockTimeSetSelect--;
					if(ClockDisplay.ClockTimeSetSelect < TIME_HOUR_SET)
					{
						ClockDisplay.ClockTimeSetSelect = TIME_DATE_SET;
					}
					break;
				
				case ALARM_SET://闹钟设置界面
					switch(Clock.AlarmClockWorkStatus)
					{
						case ALARM_STOP:
							ClockDisplay.ClockAlarmSetSelect--;
							if(ClockDisplay.ClockAlarmSetSelect < CLK_ALARM_HOUR_SET)
							{
								ClockDisplay.ClockAlarmSetSelect = CLK_ALARM_MINUTE_SET;
							}
							break;
						case ALARM_START:
							break;
						case ALARM_WORKING:
							break;
					}
					break;
				
				case STOP_WATCH://秒表设置
					break;
				
				case TIMER_SET://计时器设置
					switch(Clock.TimerWorkStatus)
					{
						case TIMER_STOP:
							ClockDisplay.ClockTimerSetSelect--;
							if(ClockDisplay.ClockTimerSetSelect < CLK_TIMER_HOUR_SET)
							{
								ClockDisplay.ClockTimerSetSelect = CLK_TIMER_SECOND_SET;
							}
							break;
						case TIMER_START:
							break;
						case TIMER_ALARM:
							break;
					}
					break;
				
				case INFO://制作者信息
					break;
			}
			break;
		
		case KEY_DIRECTION_RIGHT://方向键右
			OledCls();//OLED清屏
			switch(ClockDisplay.ClockDisplayStatus)//OLED屏幕上显示的界面
			{
				case MAIN_INTERFACE://主界面
					break;
				
				case MENU://菜单功能选择界面
				
				case CLOCK_SET://时间设置界面
					ClockDisplay.ClockTimeSetSelect++;
					if(ClockDisplay.ClockTimeSetSelect > TIME_DATE_SET)
					{
						ClockDisplay.ClockTimeSetSelect = TIME_HOUR_SET;
					}
					break;
				
				case ALARM_SET://闹钟设置界面
					switch(Clock.AlarmClockWorkStatus)
					{
						case ALARM_STOP:
							ClockDisplay.ClockAlarmSetSelect++;
							if(ClockDisplay.ClockAlarmSetSelect > CLK_ALARM_MINUTE_SET)
							{
								ClockDisplay.ClockAlarmSetSelect = CLK_ALARM_HOUR_SET;
							}
							break;
						case ALARM_START:
							break;
						case ALARM_WORKING:
							break;
					}
					break;
				
				case STOP_WATCH://秒表设置
					break;
				
				case TIMER_SET://计时器设置
					switch(Clock.TimerWorkStatus)
					{
						case TIMER_STOP:
							ClockDisplay.ClockTimerSetSelect++;
							if(ClockDisplay.ClockTimerSetSelect > CLK_TIMER_SECOND_SET)
							{
								ClockDisplay.ClockTimerSetSelect = CLK_TIMER_HOUR_SET;
							}
							break;
						case TIMER_START:
							break;
						case TIMER_ALARM:
							break;
					}
					break;
				
				case INFO://制作者信息
					break;
			}
			break;
	}
}

//OLED屏幕上时钟显示
void OledDisplay(void)
{
	switch(ClockDisplay.ClockDisplayStatus)
	{
		case MAIN_INTERFACE:
			
//			if(Clock.AlarmClockWorkStatus == ALARM_WORKING)	//闹钟响直接跳到闹钟界面
//			{
//				OledCls();//OLED清屏
//				ClockDisplay.ClockDisplayStatus = ALARM_SET;
//			}
		
			OledTimeValueShow(30,2,Clock.hour);
			OledShow6x8Char(50,2,':');
			OledTimeValueShow(60,2,Clock.minute);
			OledShow6x8Char(80,2,':');
			OledTimeValueShow(90,2,Clock.second);
			//星期显示
			switch(Clock.Week)
			{
				case Monday:
					OledShow6x8Str(40,4,"Monday");
					break;
				case Tuesday:
					OledShow6x8Str(40,4,"Tuesday");
					break;
				case Wednesday:
					OledShow6x8Str(40,4,"Wednesday");
					break;
				case Thursday:
					OledShow6x8Str(40,4,"Thursday");
					break;
				case Friday:
					OledShow6x8Str(40,4,"Friday");
					break;
				case Saturday:
					OledShow6x8Str(40,4,"Saturday");
					break;
				case Sunday:
					OledShow6x8Str(40,4,"Sunday");
					break;
			}
			//日期显示
			OledYearValueShow(35,5,Clock.year);
			OledShow6x8Char(60,5,'-');
			OledTimeValueShow(66,5,Clock.month);
			OledShow6x8Char(79,5,'-');
			OledTimeValueShow(85,5,Clock.date);
			
			OledShow6x8Str(5,7,"MENU");OledShow6x8Str(95,7,"INFO");	//底部导航选项
			break;
		
		case MENU:
			OledShow6x8Str(5,0,"----- M E N U -----");//标题
		
			OledShow6x8Str(5,2,"Clock Set");
			OledShow6x8Str(5,3,"Alarm");
			OledShow6x8Str(5,4,"Stop Watch");
			OledShow6x8Str(5,5,"Timer");
			
			OledShow6x8Str(100,ClockDisplay.ClockMenuSelect,"<-");//指向箭头
			OledShow6x8Str(5,7,"SELECT");OledShow6x8Str(95,7,"BACK");	//底部导航选项
			break;
		
		case CLOCK_SET:
			OledShow6x8Str(5,0,"---- C L O C K ----");//标题
			
			switch(ClockDisplay.ClockTimeSetSelect)//闪烁位置
			{
				case TIME_HOUR_SET:
					switch(ClockDisplay.FlickerFlag)
					{
						case APPEAR:
							OledTimeValueShow(30,2,Clock.hour);
							break;
						case DISAPPEAR:
							OledShow6x8Str(30,2,"  ");
							break;
					}
					OledShow6x8Char(50,2,':');
					OledTimeValueShow(60,2,Clock.minute);
					OledShow6x8Char(80,2,':');
					OledTimeValueShow(90,2,Clock.second);
					//星期显示
					switch(Clock.Week)
					{
						case Monday:
							OledShow6x8Str(40,4,"Monday");
							break;
						case Tuesday:
							OledShow6x8Str(40,4,"Tuesday");
							break;
						case Wednesday:
							OledShow6x8Str(40,4,"Wednesday");
							break;
						case Thursday:
							OledShow6x8Str(40,4,"Thursday");
							break;
						case Friday:
							OledShow6x8Str(40,4,"Friday");
							break;
						case Saturday:
							OledShow6x8Str(40,4,"Saturday");
							break;
						case Sunday:
							OledShow6x8Str(40,4,"Sunday");
							break;
					}
					//日期显示
					OledYearValueShow(35,5,Clock.year);
					OledShow6x8Char(60,5,'-');
					OledTimeValueShow(66,5,Clock.month);
					OledShow6x8Char(79,5,'-');
					OledTimeValueShow(85,5,Clock.date);
					break;
				case TIME_MINUTE_SET:
					switch(ClockDisplay.FlickerFlag)
					{
						case APPEAR:
							OledTimeValueShow(60,2,Clock.minute);
							break;
						case DISAPPEAR:
							OledShow6x8Str(60,2,"  ");
							break;
					}
					OledTimeValueShow(30,2,Clock.hour);
					OledShow6x8Char(50,2,':');
					//OledTimeValueShow(60,2,Clock.minute);
					OledShow6x8Char(80,2,':');
					OledTimeValueShow(90,2,Clock.second);
					//星期显示
					switch(Clock.Week)
					{
						case Monday:
							OledShow6x8Str(40,4,"Monday");
							break;
						case Tuesday:
							OledShow6x8Str(40,4,"Tuesday");
							break;
						case Wednesday:
							OledShow6x8Str(40,4,"Wednesday");
							break;
						case Thursday:
							OledShow6x8Str(40,4,"Thursday");
							break;
						case Friday:
							OledShow6x8Str(40,4,"Friday");
							break;
						case Saturday:
							OledShow6x8Str(40,4,"Saturday");
							break;
						case Sunday:
							OledShow6x8Str(40,4,"Sunday");
							break;
					}
					//日期显示
					OledYearValueShow(35,5,Clock.year);
					OledShow6x8Char(60,5,'-');
					OledTimeValueShow(66,5,Clock.month);
					OledShow6x8Char(79,5,'-');
					OledTimeValueShow(85,5,Clock.date);
					break;
				case TIME_SECOND_SET:
					switch(ClockDisplay.FlickerFlag)
					{
						case APPEAR:
							OledTimeValueShow(90,2,Clock.second);
							break;
						case DISAPPEAR:
							OledShow6x8Str(90,2,"  ");
							break;
					}
					OledTimeValueShow(30,2,Clock.hour);
					OledShow6x8Char(50,2,':');
					OledTimeValueShow(60,2,Clock.minute);
					OledShow6x8Char(80,2,':');
					//OledTimeValueShow(90,2,Clock.second);
					//星期显示
					switch(Clock.Week)
					{
						case Monday:
							OledShow6x8Str(40,4,"Monday");
							break;
						case Tuesday:
							OledShow6x8Str(40,4,"Tuesday");
							break;
						case Wednesday:
							OledShow6x8Str(40,4,"Wednesday");
							break;
						case Thursday:
							OledShow6x8Str(40,4,"Thursday");
							break;
						case Friday:
							OledShow6x8Str(40,4,"Friday");
							break;
						case Saturday:
							OledShow6x8Str(40,4,"Saturday");
							break;
						case Sunday:
							OledShow6x8Str(40,4,"Sunday");
							break;
					}
					//日期显示
					OledYearValueShow(35,5,Clock.year);
					OledShow6x8Char(60,5,'-');
					OledTimeValueShow(66,5,Clock.month);
					OledShow6x8Char(79,5,'-');
					OledTimeValueShow(85,5,Clock.date);
					break;
				case TIME_WEEK_SET:
					switch(ClockDisplay.FlickerFlag)
					{
						case APPEAR:
							//星期显示
							switch(Clock.Week)
							{
								case Monday:
									OledShow6x8Str(40,4,"Monday");
									break;
								case Tuesday:
									OledShow6x8Str(40,4,"Tuesday");
									break;
								case Wednesday:
									OledShow6x8Str(40,4,"Wednesday");
									break;
								case Thursday:
									OledShow6x8Str(40,4,"Thursday");
									break;
								case Friday:
									OledShow6x8Str(40,4,"Friday");
									break;
								case Saturday:
									OledShow6x8Str(40,4,"Saturday");
									break;
								case Sunday:
									OledShow6x8Str(40,4,"Sunday");
									break;
							}
							break;
						case DISAPPEAR:
							OledShow6x8Str(40,4,"        ");
							break;
					}
					OledTimeValueShow(30,2,Clock.hour);
					OledShow6x8Char(50,2,':');
					OledTimeValueShow(60,2,Clock.minute);
					OledShow6x8Char(80,2,':');
					OledTimeValueShow(90,2,Clock.second);
					//日期显示
					OledYearValueShow(35,5,Clock.year);
					OledShow6x8Char(60,5,'-');
					OledTimeValueShow(66,5,Clock.month);
					OledShow6x8Char(79,5,'-');
					OledTimeValueShow(85,5,Clock.date);
					break;
				case TIME_YEAR_SET:
					switch(ClockDisplay.FlickerFlag)
					{
						case APPEAR:
							OledYearValueShow(35,5,Clock.year);
							break;
						case DISAPPEAR:
							OledShow6x8Str(35,5,"    ");
							break;
					}
					OledTimeValueShow(30,2,Clock.hour);
					OledShow6x8Char(50,2,':');
					OledTimeValueShow(60,2,Clock.minute);
					OledShow6x8Char(80,2,':');
					OledTimeValueShow(90,2,Clock.second);
					//星期显示
					switch(Clock.Week)
					{
						case Monday:
							OledShow6x8Str(40,4,"Monday");
							break;
						case Tuesday:
							OledShow6x8Str(40,4,"Tuesday");
							break;
						case Wednesday:
							OledShow6x8Str(40,4,"Wednesday");
							break;
						case Thursday:
							OledShow6x8Str(40,4,"Thursday");
							break;
						case Friday:
							OledShow6x8Str(40,4,"Friday");
							break;
						case Saturday:
							OledShow6x8Str(40,4,"Saturday");
							break;
						case Sunday:
							OledShow6x8Str(40,4,"Sunday");
							break;
					}
					//日期显示
					//OledYearValueShow(35,5,Clock.year);
					OledShow6x8Char(60,5,'-');
					OledTimeValueShow(66,5,Clock.month);
					OledShow6x8Char(79,5,'-');
					OledTimeValueShow(85,5,Clock.date);
					break;
				case TIME_MONTH_SET:
					switch(ClockDisplay.FlickerFlag)
					{
						case APPEAR:
							OledTimeValueShow(66,5,Clock.month);
							break;
						case DISAPPEAR:
							OledShow6x8Str(66,5,"  ");
							break;
					}
					OledTimeValueShow(30,2,Clock.hour);
					OledShow6x8Char(50,2,':');
					OledTimeValueShow(60,2,Clock.minute);
					OledShow6x8Char(80,2,':');
					OledTimeValueShow(90,2,Clock.second);
					//星期显示
					switch(Clock.Week)
					{
						case Monday:
							OledShow6x8Str(40,4,"Monday");
							break;
						case Tuesday:
							OledShow6x8Str(40,4,"Tuesday");
							break;
						case Wednesday:
							OledShow6x8Str(40,4,"Wednesday");
							break;
						case Thursday:
							OledShow6x8Str(40,4,"Thursday");
							break;
						case Friday:
							OledShow6x8Str(40,4,"Friday");
							break;
						case Saturday:
							OledShow6x8Str(40,4,"Saturday");
							break;
						case Sunday:
							OledShow6x8Str(40,4,"Sunday");
							break;
					}
					//日期显示
					OledYearValueShow(35,5,Clock.year);
					OledShow6x8Char(60,5,'-');
					//OledTimeValueShow(66,5,Clock.month);
					OledShow6x8Char(79,5,'-');
					OledTimeValueShow(85,5,Clock.date);
					break;
				case TIME_DATE_SET:
					switch(ClockDisplay.FlickerFlag)
					{
						case APPEAR:
							OledTimeValueShow(85,5,Clock.date);
							break;
						case DISAPPEAR:
							OledShow6x8Str(85,5,"  ");
							break;
					}
					OledTimeValueShow(30,2,Clock.hour);
					OledShow6x8Char(50,2,':');
					OledTimeValueShow(60,2,Clock.minute);
					OledShow6x8Char(80,2,':');
					OledTimeValueShow(90,2,Clock.second);
					//星期显示
					switch(Clock.Week)
					{
						case Monday:
							OledShow6x8Str(40,4,"Monday");
							break;
						case Tuesday:
							OledShow6x8Str(40,4,"Tuesday");
							break;
						case Wednesday:
							OledShow6x8Str(40,4,"Wednesday");
							break;
						case Thursday:
							OledShow6x8Str(40,4,"Thursday");
							break;
						case Friday:
							OledShow6x8Str(40,4,"Friday");
							break;
						case Saturday:
							OledShow6x8Str(40,4,"Saturday");
							break;
						case Sunday:
							OledShow6x8Str(40,4,"Sunday");
							break;
					}
					//日期显示
					OledYearValueShow(35,5,Clock.year);
					OledShow6x8Char(60,5,'-');
					OledTimeValueShow(66,5,Clock.month);
					OledShow6x8Char(79,5,'-');
					//OledTimeValueShow(85,5,Clock.date);
					break;
			}
		
			OledShow6x8Str(5,7,"COMFIRM");	//底部导航选项
			break;
		
		case ALARM_SET:
			OledShow6x8Str(5,0,"---- A L A R M ----");//标题
		
			switch(Clock.AlarmClockWorkStatus)
			{
				case ALARM_STOP://闹钟关闭
					switch(ClockDisplay.ClockAlarmSetSelect)
					{
						case CLK_ALARM_HOUR_SET:
							switch(ClockDisplay.FlickerFlag)
							{
								case APPEAR:
									OledTimeValueShow(40,4,Clock.alarm_hour);
									break;
								case DISAPPEAR:
									OledShow6x8Str(40,4,"  ");
									break;
							}
							OledShow6x8Char(60,4,':');
							OledTimeValueShow(70,4,Clock.alarm_minute);
							break;
						case CLK_ALARM_MINUTE_SET:
							switch(ClockDisplay.FlickerFlag)
							{
								case APPEAR:
									OledTimeValueShow(70,4,Clock.alarm_minute);
									break;
								case DISAPPEAR:
									OledShow6x8Str(70,4,"  ");
									break;
							}
							OledTimeValueShow(40,4,Clock.alarm_hour);
							OledShow6x8Char(60,4,':');
							break;
					}
				
					OledShow6x8Str(35,2,"ALARM OFF");
					OledShow6x8Str(5,7,"TURN ON");OledShow6x8Str(95,7,"BACK");	//底部导航选项
					break;
				case ALARM_START://闹钟开启
					OledTimeValueShow(40,4,Clock.alarm_hour);
					OledShow6x8Char(60,4,':');
					OledTimeValueShow(70,4,Clock.alarm_minute);
					OledShow6x8Str(38,2,"ALARM ON");
					OledShow6x8Str(5,7,"TURN OFF");OledShow6x8Str(95,7,"BACK");	//底部导航选项
					break;
				case ALARM_WORKING://闹钟正在响铃
					OledTimeValueShow(40,4,Clock.alarm_hour);
					OledShow6x8Char(60,4,':');
					OledTimeValueShow(70,4,Clock.alarm_minute);
					OledShow6x8Str(22,2,"ALARM WORKING");
					OledShow6x8Str(5,7,"TURN OFF");//底部导航选项
					break;
				
			}
			break;
		
		case STOP_WATCH:
			OledShow6x8Str(5,0,"---- STOP WATCH ----");//标题
		
			OledTimeValueShow(10,3,Clock.stop_hour);
			OledShow6x8Char(30,3,':');
			OledTimeValueShow(40,3,Clock.stop_minute);
			OledShow6x8Char(60,3,':');
			OledTimeValueShow(70,3,Clock.stop_second);
			OledShow6x8Char(90,3,':');
			OledTimeValueShow(100,3,Clock.stop_millisecond);
		
			switch(Clock.StopWatchStatus)
			{
				case WATCH_STOP://秒表停止工作
					OledShow6x8Str(5,7,"START");OledShow6x8Str(95,7,"BACK");	//底部导航选项
					break;
				case WATCH_START://秒表开始工作
					OledShow6x8Str(5,7,"PAUSE");OledShow6x8Str(95,7,"BACK");	//底部导航选项
					break;
				case WATCH_PAUSE://秒表暂停
					OledShow6x8Str(5,7,"CONTINUE");OledShow6x8Str(90,7,"CLEAR");	//底部导航选项
					break;
			}
			break;
		
		case TIMER_SET:
			OledShow6x8Str(5,0,"---- T I M E R ----");//标题
		
			switch(Clock.TimerWorkStatus)
			{
				case TIMER_STOP://计时器停止工作
					switch(ClockDisplay.ClockTimerSetSelect)
					{
						case CLK_TIMER_HOUR_SET:
							switch(ClockDisplay.FlickerFlag)
							{
								case APPEAR:
									OledTimeValueShow(30,4,Clock.timer_hour);
									break;
								case DISAPPEAR:
									OledShow6x8Str(30,4,"  ");
									break;
							}
							OledShow6x8Char(50,4,':');
							OledTimeValueShow(60,4,Clock.timer_minute);
							OledShow6x8Char(80,4,':');
							OledTimeValueShow(90,4,Clock.timer_second);
							break;
						case CLK_TIMER_MINUTE_SET:
							switch(ClockDisplay.FlickerFlag)
							{
								case APPEAR:
									OledTimeValueShow(60,4,Clock.timer_minute);
									break;
								case DISAPPEAR:
									OledShow6x8Str(60,4,"  ");
									break;
							}
							OledTimeValueShow(30,4,Clock.timer_hour);
							OledShow6x8Char(50,4,':');
							OledShow6x8Char(80,4,':');
							OledTimeValueShow(90,4,Clock.timer_second);
							break;
						case CLK_TIMER_SECOND_SET:
							switch(ClockDisplay.FlickerFlag)
							{
								case APPEAR:
									OledTimeValueShow(90,4,Clock.timer_second);
									break;
								case DISAPPEAR:
									OledShow6x8Str(90,4,"  ");
									break;
							}
							OledTimeValueShow(30,4,Clock.timer_hour);
							OledShow6x8Char(50,4,':');
							OledTimeValueShow(60,4,Clock.timer_minute);
							OledShow6x8Char(80,4,':');
							break;
					}
				
					OledShow6x8Str(35,2,"TIMER OFF");
					OledShow6x8Str(5,7,"TURN ON");OledShow6x8Str(95,7,"BACK");	//底部导航选项
					break;
				case TIMER_START://计时器开始计时
					OledTimeValueShow(30,4,Clock.timer_hour);
					OledShow6x8Char(50,4,':');
					OledTimeValueShow(60,4,Clock.timer_minute);
					OledShow6x8Char(80,4,':');
					OledTimeValueShow(90,4,Clock.timer_second);
				
					OledShow6x8Str(38,2,"TIMER ON");
					OledShow6x8Str(5,7,"TURN OFF");OledShow6x8Str(95,7,"BACK");	//底部导航选项
					break;
				case TIMER_ALARM://计时器报警
					switch(ClockDisplay.FlickerFlag)
					{
						case APPEAR:
							OledTimeValueShow(30,4,Clock.timer_hour);
							OledShow6x8Char(50,4,':');
							OledTimeValueShow(60,4,Clock.timer_minute);
							OledShow6x8Char(80,4,':');
							OledTimeValueShow(90,4,Clock.timer_second);
							break;
						case DISAPPEAR:
							OledShow6x8Str(30,4,"  ");
							OledShow6x8Str(60,4,"  ");
							OledShow6x8Str(90,4,"  ");
							break;
					}
				
					OledShow6x8Str(22,2,"TIMER WORKING");
					OledShow6x8Str(5,7,"TURN OFF");//底部导航选项
					break;
			}
		
			break;
		
		case INFO://制作者信息
			OledShow6x8Str(5,0,"----- I N F O -----");//标题
		
			OledShow6x8Str(0,2,"name:");OledShow6x8Str(60,2,"ID:");
			OledShow6x8Str(0,3,"fukai");OledShow6x8Str(60,3,"1600301221");
			OledShow6x8Str(0,4,"mahaoxuan");OledShow6x8Str(60,4,"1600301224");
		
			OledShow6x8Str(95,7,"BACK");	//底部导航选项
			break;
	}
}



//用户界面显示
void UserInterface(void)
{
	FunctionSelection();	//功能选择部分
	OledDisplay();
}








